// 定义四个GPIO引脚
#define RL 9
#define RH 8
#define RP 7
#define LL 6
#define LH 5
#define LP 4
#define PWM_SPEED 200  //0~255

void setup() {
  Serial.begin(115200);

  // 设置引脚模式
  pinMode(RL, OUTPUT);
  pinMode(RH, OUTPUT);
  pinMode(LL, OUTPUT);
  pinMode(LH, OUTPUT);

  // 初始状态设为停止
  stopAll();

  Serial.println("ESP32-S3引脚初始化完成");
}

void r_clockTurn(int p) {
  digitalWrite(RL, HIGH);
  digitalWrite(RH, LOW);
  analogWrite(RP, p);
}

void l_clockTurn(int p) {
  digitalWrite(LL, HIGH);
  digitalWrite(LH, LOW);
  analogWrite(LP, p);
}

void r_unclockTurn(int p) {
  digitalWrite(RL, LOW);
  digitalWrite(RH, HIGH);
  analogWrite(RP, p);
}

void l_unclockTurn(int p) {
  digitalWrite(LL, LOW);  
  digitalWrite(LH, HIGH);   
  analogWrite(LP, p);
}

void stopAll() {
  digitalWrite(RL, LOW);
  digitalWrite(RH, LOW);
  digitalWrite(LL, LOW);
  digitalWrite(LH, LOW);
}

void loop() {
  int p=150;
  //for(int i=0;i<=p/10;i++){l_clockTurn(i*10);delay(1000/(p/10));}
  // 顺时针旋转
  l_clockTurn(p);
  Serial.println("右顺时针旋转");
  delay(3000);
  stopAll();
  delay(500);
  //for(int i=0;i<=p/10;i++){l_clockTurn(p-i*10);delay(1000/(p/10));}
  // 逆时针旋转
  //for(int i=0;i<=p/10;i++){l_clockTurn(i*10);delay(1000/(p/10));}
  l_unclockTurn(p);
  Serial.println("右逆时针旋转");
  delay(3000);
  stopAll();
  delay(500);
  //for(int i=0;i<=p/10;i++){l_clockTurn(p-i*10);delay(1000/(p/10));}
    // 顺时针旋转

}
